import java.io.*;
import java.awt.*; 
import java.awt.event.*;
import javax.swing.*; 

public class StudentFileReader {

	protected static int id;
	protected static String name;
	protected static String course;
	protected static int year;
	protected static String classCode;
	protected static String schedule;


   public StudentFileReader() throws Exception {

    	try {
    		read();

    		ObjectInputStream fileReader = new ObjectInputStream(new FileInputStream("students.dat"));
    		Student[] studs = (Student[]) fileReader.readObject();

    		// List the records
	        for (int i = 0; i < studs.length; i++) {
	        	System.out.printf("%7d %-35s %-5s %1d %-6s%n",studs[i].getID(), studs[i].getName(), studs[i].getCourse(), studs[i].getYear(), studs[i].getClassCode(),studs[i].getSchedule());
	        }
    	} catch (FileNotFoundException fnfe) {

    		fnfe.printStackTrace();
    	} catch (Exception e) {
    		e.printStackTrace();
    	}
   }


	//Reads and desirializes the data file with ObjectInputStream and FileInputStream, constructs the data with class Student then saves it to stud[]...
	private void read() throws Exception{
		File up = new File("students_updated.dat");
		ObjectInputStream updated = new ObjectInputStream(new FileInputStream(up));
		StudentMainClass.stud = (Student[]) updated.readObject();
		updated.close();
	}
}